package graph;

import java.util.HashSet;
import java.util.Set;
import java.util.Stack;

public class Code02_DFS {
    public static void dfs(Node node){
        Stack<Node> stack = new Stack<Node>();
        Set<Node> visited = new HashSet<Node>();
        stack.push(node);
        visited.add(node);
        System.out.println(node.value);
        while(!stack.isEmpty()){
            Node cur = stack.pop();
            for(Node next : cur.nexts){
                if(!visited.contains(next)){
                    stack.push(cur);
                    stack.push(next);
                    visited.add(next);
                    System.out.println(next.value);
                    break;
                }
            }
        }
    }
}
